fig.path <- "results/graph/"
fig.name3 <- paste0(fig.path, "app_fig_e01.pdf")



pal <- c("#FF8C00", "#A034F0")
db <- na.omit(Re[ , c("id", "county", "year", "treat_10", "par.onl.sh", "tot.reg", "pop")]) %>%
  subset(year < 1915  ) %>%
  mutate(fy = factor(year))

sumrepdat <- Rmisc::summarySE(db, measurevar = "par.onl.sh",
groupvars=c("treat_10", "fy"))

db.simple <- db %>% 
 group_by(year, treat_10) %>% 
  summarize_at(c("par.onl.sh"), mean, na.rm = TRUE)

db$fc <- factor(db$county )
mod <- lm(data = db, par.onl.sh~ log(1+pop)+ 0)
db$parhat <- fitted(mod)
db$pareps <- db$par.onl.sh - db$parhat

db.simple <- db %>%
 group_by(year, treat_10) %>% 
 summarize_at(c( "par.onl.sh","pareps"), mean, na.rm = TRUE)

ptre.simple<- ggplot(db.simple, aes(x = year, y = par.onl.sh)) +
    # geom_point( aes(col = treat_10, shape = treat_10)) +
    geom_line( aes(col = treat_10, linetype = treat_10)) +
    geom_vline(xintercept = 1913, colour = "grey", linetype = "solid") +
    scale_color_manual(values = pal, name = "March") +
    scale_fill_manual(values = pal, name = "March") +
    # scale_shape_manual(values  =c(1,17), name = "March") + 
    scale_linetype_manual(values = c(2,4), name = "March") + 
    theme_light() +
    ylim(0.10,0.2) +
    labs( x = "Year" , y = "Share of Local Electors") +
theme(legend.position = "bottom",
      legend.direction = "horizontal",
     panel.grid.minor = element_blank(),  # Major grid lines
) 

ggsave(plot = ptre.simple, fig.name3, width = 8, height = 8*0.8*a4ratio)
rm(list=
    setdiff(ls()[sapply(ls(), function(x) any(class(get(x)) == 'data.frame'))],
    c("Re","Ind")))